{% extends "app/base_site.html" %}

{% block title %} 系统维护 {% endblock title %}

{% block stylesheets %}
  {{ block.super }}
{% endblock stylesheets %}



{% block content %}

  <div class="right_col" role="main">
    <div class="">

        <div class="row">
        <div class="col-md-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>系统维护
                 <span id="top_loading" ><img class="top_loading_img" src="/static/images/load.gif" alt="loading">加载中</span>
                 <span id="top_msg">{{top_msg}}</span>
              </h2>
              <div class="clearfix"></div>
            </div>
            <div class="x_content">

              <table class="table table-striped projects">
                <thead>
                  <tr>
                    <th>服务名称</th>
                    <th>启动时间</th>
                    <th>状态</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody id="data">
                </tbody>
              </table>

            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
{% endblock content %}

{% block javascripts %}
  {{ block.super }}

<script>
    let eleData = $("#data");
    let ele_top_loading = $("#top_loading");
    let ele_top_msg= $("#top_msg");
    function f_handle(app,handle){
        ele_top_loading.show();
        $.ajax({
               url: '/system/getHandle',
               type: "get",
               async: true,
               data: {"app":app,"handle":handle},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myAlert("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                   ele_top_loading.hide();
                   let top_msg = res.top_msg;
                   ele_top_msg.html(top_msg);

                   if(1000 === res.code){
                        myAlert(res.msg,"success",1000);
                        setTimeout(function () {
                            f_getIndex();
                         }, 1000);

                   }else{
                        myAlert(res.msg,"error");
                   }
               }
            });
    }
    function f_getIndex() {
        ele_top_loading.show();
        $.ajax({
               url: '/system/getIndex',
               type: "get",
               async: true,
               data: {},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myAlert("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                   ele_top_loading.hide();
                   let top_msg = res.top_msg;
                   ele_top_msg.html(top_msg);

                   if(1000 === res.code){
                       eleData.html("");
                       let data = res.data;
                       let data_length = data.length;

                       let html = "";

                       if(0===data_length){
                          html += "<tr class=\"even pointer\"><td colspan='4'>暂无数据</td></tr>";
                       }else{
                            for (let i = 0; i < data_length; i++) {
                               let d = data[i];

                               html += "<tr class=\"even pointer\">";
                               html += "<td>"+d["name"]+"</td>";
                               html += "<td>"+d["create_date_str"]+"</td>";

                               if("Admin" === d["name_en"]){
                                    html += "<td><span class=\"btn-success btn-xs\">运行中</span></td>";
                                    html += "<td></td>";
                               }else{
                                    if(d["state"]===1){ //在线
                                       html += "<td><span class=\"btn-success btn-xs\">运行中</span></td>";
                                       html += "'<td><a class='sun-a-label'  href=\"javascript:f_handle('"+d["name_en"]+"','restart')\" ><i class=\"fa fa-hourglass-start\"></i> 重启</a>";
                                       html += "</td>";
                                       //html += "<a class='sun-a-label'  href=\"javascript:f_handle('"+d["name_en"]+"','stop')\" ><i class=\"fa fa-stop\"></i> 停止</a></td>";
                                   }else{
                                       html += "<td><span class=\"btn-danger btn-xs\">未运行</span></td>";
                                       html += "<td><a class='sun-a-label'  href=\"javascript:f_handle('"+d["name_en"]+"','start')\"  ><i class=\"fa fa-hourglass-start\"></i> 启动</a></td>";
                                   }
                               }

                               html += "</tr>";
                           }
                        }
                        eleData.html(html);

                   }else{
                        myAlert(res.msg,"error");
                   }
               }
            });

    }
    window.onload = function (){
        f_getIndex();
    };

</script>
{% endblock javascripts %}


